package com.yaxi.multipkid;

import android.text.InputFilter;
import android.text.Spanned;

/**
 * @author yaxi
 * @date 2019/1/11
 */
public class UpperLimitFilter implements InputFilter {

    private double upper = Double.MAX_VALUE;

    public UpperLimitFilter(double upper) {
        this.upper = upper;
    }

    @Override
    public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {

        CharSequence defore = dest.subSequence(0, dstart);
        CharSequence after = dest.subSequence(dend, dest.length());

        CharSequence result = String.format("%s%s%s",defore,source.subSequence(start,end),after);

        try {
            double v = Double.parseDouble(String.valueOf(result));
//            if (v > upper)
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }


        return null;
    }
}
